<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //闭包的应用场景
        // function fn(num){  //调用了三次
        //   return num*2
        // }  
        function fun(){  //调用了一次
            let cache={}
            return function(num){
              if(cache[num]){              
                return cache[num]
              }else{
                console.log(22)
                cache[num]=num*2
                return cache[num]
              }
            }
        }
        let fn=fun()
        fn(2)
        fn(2)
        fn(2)    
    </script>
</body>
</html>
